package com.boliq.demo;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.boliq.demo.adapter.MyAdapter;
import com.boliq.demo.adapter.MyAdapter2;
import com.boliq.demo.bean.UserBean;

public class RecyclerViewActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
//    private MyAdapter myAdapter;
    private MyAdapter2 myAdapter2;
    private Button addDataBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);
        mRecyclerView = findViewById(R.id.rv_content);
        addDataBtn = findViewById(R.id.btn_add_data);

        //recycelrview 必须要调用setLayoutManger 才能显示出列表
        LinearLayoutManager manager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(manager);

//        myAdapter = new MyAdapter();
        myAdapter2 = new MyAdapter2();
        //和提供数据及展示的适配器关联
        mRecyclerView.setAdapter(myAdapter2);

        addDataBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserBean bean = new UserBean();

                if(myAdapter2.getData().size()==0){
                    bean.setUserName("1  如何看待郑州一少年扶起\n    倒地老人，垫付的药费要\n    不回来，老人却说：  [我\n    良心过得去]  ？");
                    bean.setHeadID(R.drawable.new_1);
                }
                if(myAdapter2.getData().size()==1){
                    bean.setUserName("2  一个程序员的水平能差到\n    什么程度？");
                    bean.setHeadID(R.drawable.new_2);
                }
                if(myAdapter2.getData().size()==2){
                    bean.setUserName("3  如何看待 3 月 1 日教育\n    部公布撤销 518 个本科\n    专业？您的专业被撤销了\n    吗？");
                    bean.setHeadID(R.drawable.new_3);
                }
                if(myAdapter2.getData().size()==3){
                    bean.setUserName("4  你有哪些看过五遍以上的\n    经典电源？");
                    bean.setHeadID(R.drawable.new_4);
                }
                if(myAdapter2.getData().size()==4){
                    bean.setUserName("5  哪一个瞬间，你发现祖国\n    比想象的更强大?");
                    bean.setHeadID(R.drawable.new_5);
                }
                if(myAdapter2.getData().size()==5){
                    bean.setUserName("6  如何看待  [辣笔小球]  忏\n    悔视频曝光：称自己的行");
                    bean.setHeadID(R.drawable.new_6);
                }

                myAdapter2.addData(bean);
            }
        });
    }
}
